<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">合利宝代偿取现列表</ui:define>
    <ui:define name="content">


        <h:form>
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         actionListener="#{compensationOrderListBean.onSearch()}"
                                         onstart="PF('doing').show()"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{compensationOrderListBean.onReset()}" icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="合利宝订单"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>

                        <div class="ui-g-1">
                            <p:outputLabel value="时间"/>
                        </div>
                        <div class="ui-g-3">
                            <p:calendar
                                    id="startTime" styleClass="autoWidthCalendar"
                                    value="#{compensationOrderListBean.$.startTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATETIME_FORMAT')}"/>
                            <span>—</span>
                            <p:calendar
                                    id="endTime" styleClass="autoWidthCalendar"
                                    value="#{compensationOrderListBean.$.endTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATETIME_FORMAT')}"/>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="产品"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectCheckboxMenu id="productIds" value="#{compensationOrderListBean.$.productIds}"
                                                  updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                <f:selectItems value="#{compensationOrderListBean.commProductIds}" var="prod"
                                               itemValue="#{prod.productId}" itemLabel="#{prod.name}(#{prod.productId})"/>
                            </p:selectCheckboxMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="渠道"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectCheckboxMenu id="channelIds" value="#{compensationOrderListBean.$.channelIds}"
                                                  updateLabel="true" multiple="true" filter="true" filterMatchMode="contains">
                                <f:selectItems value="#{compensationOrderListBean.commProductChannels}" var="channel"
                                               itemValue="#{channel.channelCode}" itemLabel="#{channel.channelName}(#{channel.channelCode})"/>
                            </p:selectCheckboxMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="用户类型"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="userType" value="#{compensationOrderListBean.$.userType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="老用户" itemValue="1"/>
                                <f:selectItem itemLabel="新用户" itemValue="2"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="订单号"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="parentOrderId" value="#{compensationOrderListBean.$.orderId}"/>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="手机号"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="phone" value="#{compensationOrderListBean.$.phone}"/>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="金额区间"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText style="width: 47%"
                                         value="#{compensationOrderListBean.$.minAmount}"/>
                            <span>—</span>
                            <p:inputText style="width: 47%"
                                         value="#{compensationOrderListBean.$.maxAmount}"/>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="订单状态"/>
                        </div>
                        <div class="ui-g-3">

                            <p:selectOneMenu value="#{compensationOrderListBean.$.status}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{compensationOrderListBean.dictionaries[DictionaryCode.COMPENSATION_ORDER_STATUS]}"
                                        var="dic"
                                        itemLabel="#{dic.name}-#{dic.value1}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="入口"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="from" value="#{compensationOrderListBean.$.from}"/>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="是否使用免息券"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="isUseCoupon" value="#{compensationOrderListBean.$.isUseCoupon}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItem itemLabel="是" itemValue="1"/>
                                <f:selectItem itemLabel="否" itemValue="0"/>
                            </p:selectOneMenu>
                        </div>

                    </div>
                    <div class="ui-g-12 card">
                        <p:panelGrid>
                            <f:facet name="header">
                                <p:row>
                                    <p:column >订单金额</p:column>
                                    <p:column >成功金额</p:column>
                                    <p:column >手续费</p:column>
                                    <p:column >订单数</p:column>
                                    <p:column>成功数</p:column>
                                </p:row>

                            </f:facet>

                            <p:row>
                                <p:column >
                                    <h:outputText value="#{compensationOrderListBean.total.totalOrderAmount}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column >
                                    <h:outputText value="#{compensationOrderListBean.total.totalSuccessOrderAmount}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column >
                                    <h:outputText value="#{compensationOrderListBean.total.totalFee}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column >
                                    <h:outputText value="#{compensationOrderListBean.total.orderCount}"/>
                                </p:column>
                                <p:column >
                                    <h:outputText value="#{compensationOrderListBean.total.successOrderCount}"/>
                                </p:column>
                            </p:row>
                        </p:panelGrid>
                    </div>

                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="record"
                                     value="#{compensationOrderListBean.lazyDataModel}"
                                     rows="#{constants:get('ROWS')}"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     scrollWidth="97%"
                                     reflow="true"
                                     selection=""
                                     resizableColumns="true">
                            <p:column headerText="时间" style="text-align:center;">
                                <h:outputText value="#{record.createTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="订单号" style="text-align:center;">
                                <h:outputText value="#{record.id}"/>
                            </p:column>
                            <p:column headerText="产品名称" style="text-align:center;">
                                <h:outputText value="#{record.productName}"/>
                            </p:column>
                            <p:column headerText="渠道号" style="text-align:center;">
                                <h:outputText value="#{record.channelName}"/>
                            </p:column>
                            <p:column headerText="用户类型" style="text-align:center;">
                                <h:outputText value="老用户" rendered="#{record.userType==1}"/>
                                <h:outputText value="新用户" rendered="#{record.userType==2}"/>
                            </p:column>
                            <p:column headerText="姓名" style="text-align:center;">
                                <h:outputText value="#{record.username}"/>
                            </p:column>
                            <p:column headerText="手机号" style="text-align:center;">
                                <h:outputText value="#{record.phone}"/>
                            </p:column>
                            <p:column headerText="订单类型" style="text-align:center;">
                                <h:outputText value="代偿"  rendered="#{record.orderType==0}"/>
                                <h:outputText value="取现"  rendered="#{record.orderType==1}"/>
                            </p:column>
                            <p:column headerText="交易金额" style="text-align:center;">
                                <h:outputText value="#{record.amount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="订单状态" style="text-align:center;">
                                <h:outputText
                                        value="#{compensationOrderListBean.translate(DictionaryCode.COMPENSATION_ORDER_STATUS,record.status)}"/>
                            </p:column>
                            <p:column headerText="手续费（元）" style="text-align:center;">
                                <h:outputText value="#{record.fee}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="入口" style="text-align:center;">
                                <h:outputText value="#{record.from}"/>
                            </p:column>
                            <p:column headerText="扣款失败原因" style="text-align:center;">
                                <h:outputText value="#{record.remark}"/>
                            </p:column>
                            <p:column headerText="使用免息券" style="text-align:center;">
                                <h:outputText value="否"  rendered="#{record.isUseCoupon==0}"/>
                                <h:outputText value="是"  rendered="#{record.isUseCoupon==1}"/>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>